﻿package net.wangit.dev.version;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.context.ActionContextHelper;
import net.wangit.context.LocalContext;
import net.wangit.support.UnitInterceptor;

public class OutputUI implements UnitInterceptor {

	public static final String KEY = "net.wangit.dev.version.OutputUI.type";

	public OutputUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String type = getComponentType();
		unit.getElement("type").setDefaultValue(type);
		return unit.write(ac);
	}

	public static String getComponentType() {
		ActionContext ac = LocalContext.getLocalContext().getActionContext();
		String defaultType = Integer.toString(2);
		return ActionContextHelper.getRequest2Session(ac, "output.type",
				"net.wangit.dev.version.OutputUI.type", defaultType);
	}
}
